package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexSearchVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    @Operation(summary = "上架专辑接口")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        searchService.upperAlbum(albumId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "下架接口")
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable(value = "albumId") Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "批量上架")
    @GetMapping("batchUpperAblum")
    public Result batchUpperAblum(){
        for (int i = 1; i < 1599; i++) {
            searchService.upperAlbum((long) i);
        }
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "专辑搜索接口")
    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.build(albumSearchResponseVo,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "根据一级分类id查询专辑数据")
    @GetMapping("/channel/{category1Id}")
    public Result<List<AlbumInfoIndexSearchVo>> channel(@PathVariable(value = "category1Id") Long c1Id){
        List<AlbumInfoIndexSearchVo> albumInfoIndexSearchVo = searchService.channel(c1Id);
        return Result.build(albumInfoIndexSearchVo,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "关键字自动补全接口")
    @GetMapping("/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable(value = "keyword") String keyword){
        List<String> list = searchService.completeSuggest(keyword);
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }


}

